package com.future.controller;

import com.future.pojo.Users;
import com.future.service.AdminService;
import com.future.service.SingerService;
import io.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/singer")
//@MapperScan(basePackages = { "com.future.service"})
public class SingerController {
    static Logger logger = Logger.getLogger(MusicController.class);

    @Autowired
    private SingerService singerService;
    @Autowired
    private AdminService adminService;

    @ApiOperation(value = "歌手推荐")
    @RequestMapping("/query")
    public String six(Model model) {

        List<Users> list = singerService.querySixSinger();
        model.addAttribute("Singer", list);
        return "allMusic.jsp";
    }



    @ApiOperation(value = "查询全部歌手")
    @GetMapping("/allSinger")                                 //测试通过
    public String querySinger(Model model,int page) {
        int count = adminService.singerCount();
        int sumPage = 0;
        if (count % 10 != 0) {
            sumPage=count/10+1;
        }else{
            sumPage=count/10;
        }
        if(page==0){
            List<Users> list = adminService.querySinger((page+1)*10-10,10);
            model.addAttribute("page",page+1);
            model.addAttribute("sumPage",sumPage);
            model.addAttribute("Users", list);
            return "/L-html/L-homepage/L-allSingers.html";
        }else if (page>sumPage){
            List<Users> list = adminService.querySinger((page-1)*10-10,10);
            model.addAttribute("page",page-1);
            model.addAttribute("sumPage",sumPage);
            model.addAttribute("Users", list);
            return "/L-html/L-homepage/L-allSingers.html";
        }else{
            List<Users> list = adminService.querySinger(page*10-10,10);
            model.addAttribute("page",page);
            model.addAttribute("sumPage",sumPage);
            model.addAttribute("Users", list);
            return "/L-html/L-homepage/L-allSingers.html";
        }

    }

}
